package com.nightpiter.view.drawer.dynamic;

import com.nightpiter.model.objects.Transfer;
import com.nightpiter.model.objects.Tunnel;

/**
 * @author Eldar Abusalimov (eldar.abusalimov@gmail.com)
 * 
 */
class PrimitiveBacillus extends Bacillus {

	@SuppressWarnings("unused")
	private BacillusUltimate bacillusUltimate;

	/**
	 * 
	 * @param bacillusUltimate
	 * @param evenAmoeba
	 * @param oddAmoeba
	 */
	public PrimitiveBacillus(BacillusUltimate bacillusUltimate,
			PrimitiveAmoeba evenAmoeba, PrimitiveAmoeba oddAmoeba) {
		this.bacillusUltimate = bacillusUltimate;
		this.evenAmoeba = evenAmoeba;
		this.oddAmoeba = oddAmoeba;
		evenAmoeba.addNeighborPrimitive(oddAmoeba, this);
		oddAmoeba.addNeighborPrimitive(evenAmoeba, this);
		bacillusUltimate.addPrimitiveBacillus(this);
	}

	public void addTransfer(PrimitiveAmoeba fromAmoeba,
			PrimitiveAmoeba toAmoeba, Transfer transfer) {

		for (TransferPart part : transferParts) {
			if (part.opposite == (fromAmoeba != evenAmoeba)) {
				return;
			}
		}
		TransferPart part = new TransferPart();
		part.opposite = fromAmoeba != evenAmoeba;
		part.transfer = transfer;

		transferParts.add(part);
		transfersSize++;

	}

	public void addTunnel(PrimitiveAmoeba fromAmoeba, PrimitiveAmoeba toAmoeba,
			Tunnel tunnel) {

		for (TunnelPart part : tunnelParts) {
			if (part.tunnel.getLine() == tunnel.getLine()) {
				part.singleSide = false;
				return;
			}
		}
		TunnelPart part = new TunnelPart();
		part.opposite = fromAmoeba != evenAmoeba;
		part.color = tunnel.getLine().getColor();
		part.tunnel = tunnel;

		tunnelParts.add(part);
		tunnelsSize++;

	}

}
